using System;
using System.Collections.Generic;
using System.Text;
using Reflector.CodeModel;
using System.Diagnostics;

namespace LanguageWriterHelper
{
    [DebuggerStepThrough()]
    public class VisitorManager
    {
        MetadataVisitor metadataVisitor;
        StatementVisitor statementVisitor;
        ReflectorVisitor reflectorVisitor;
        ExpressionVisitor expressionVisitor;
        ILanguageWriterConfiguration configuration;
        ILVisitor ilVisitor;
        IFormatter formatter;
        Dictionary<string, bool> visibilityConfiguration;

        public VisitorManager(IFormatter formatter, ILanguageWriterConfiguration configuration, Dictionary<string, bool> visibilityConfiguration)
        {
            this.formatter = formatter;
            this.configuration = configuration;
            this.visibilityConfiguration = visibilityConfiguration;
        }

        public IFormatter Formatter
        {
            get { return formatter; }
        }

        [DebuggerStepThrough()]
        public void Write(string value)
        {
            formatter.WriteLiteral(value);
            formatter.WriteLine();
        }

        public ILanguageWriterConfiguration Configuration
        {
            get { return configuration; }
        }

        public Dictionary<string, bool> VisibilityConfiguration
        {
            get { return visibilityConfiguration; }
        }

        public MetadataVisitor MetadataVisitor
        {
            get 
            {
                if (metadataVisitor == null)
                {
                    metadataVisitor = new MetadataVisitor();
                    metadataVisitor.Manager = this;
                }
                return metadataVisitor; 
            }
        }

        public ILVisitor ILVisitor
        {
            get
            {
                if (ilVisitor == null)
                {
                    ilVisitor = new ILVisitor();
                    ilVisitor.Manager = this;
                }
                return ilVisitor;
            }
        }

        public StatementVisitor StatementVisitor
        {
            get 
            {
                if (statementVisitor == null)
                {
                    statementVisitor = new StatementVisitor();
                    statementVisitor.Manager = this;
                }
                return statementVisitor; 
            }
        }
                
        public ReflectorVisitor ReflectorVisitor
        {
            get 
            {
                if (reflectorVisitor == null)
                {
                    reflectorVisitor = new ReflectorVisitor();
                    reflectorVisitor.Manager = this;
                }
                return reflectorVisitor; 
            }
        }
                
        public ExpressionVisitor ExpressionVisitor
        {
            get 
            {
                if (expressionVisitor == null)
                {
                    expressionVisitor = new ExpressionVisitor();
                    expressionVisitor.Manager = this;
                }
                return expressionVisitor; 
            }
        }
    }
}
